var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = getApp();

Component({
    properties: {
        prop_goods_info: {
            type: null
        },
        goodsId: {
            type: Number
        },
        goodsType: {
            type: String
        },
        hoet: {
            type: null
        }
    },
    data: {
        goodsInfo: {},
        rechargeType: {},
        rechargeItem: {},
        rechargeSpecId: 0,
        displayOptions: [],
        optionsId: 0,
        show1: !1,
        service_QRcode: "",
        service_mobile: "",
        cservice: "",
        likeArr: [],
        swipeIndex: 0,
        mobile: "",
        bannerUrl: "",
        posterShow: !1,
        tapSelect: !1,
        AccountList: [],
        currentAccount: null,
        editUserShow: !1,
        form_account_name: "",
        form_account_number: "",
        form_charge_type: 1,
        addressShow_p: !1,
        form_province: "",
        form_city: "",
        selectUserShow: !1,
        radioAccount: "1",
        tipsShow: !1,
        desc_text: "",
        codeArr: [ {
            value: "",
            focusa: !0
        }, {
            value: "",
            focusa: !1
        }, {
            value: "",
            focusa: !1
        }, {
            value: "",
            focusa: !1
        }, {
            value: "",
            focusa: !1
        }, {
            value: "",
            focusa: !1
        } ],
        codeValue: "",
        isProvinceShow: !1
    },
    ready: function() {
        console.log(this.properties.prop_goods_info);
        var t = this.properties.prop_goods_info, e = {}, a = this.data.goodsInfo = t.get_goods, o = a.has_many_specs[0];
        this._handClickSpecs(o.specitem[0]), e.goodsInfo = a, e.rechargeType = o, t && t.plugin && t.plugin.electricityBillPro && (e.bannerUrl = t.plugin.electricityBillPro.banner), 
        t.customer_service && (e.service_QRcode = t.customer_service.service_QRcode, e.service_mobile = t.customer_service.service_mobile, 
        e.cservice = t.customer_service.cservice), e.desc_text = t.plugin.electricityBillPro.desc;
        var c = a.show_push.slice(0, 30), i = [];
        c.forEach(function(t, e) {
            var a = Math.floor(e / 6);
            i[a] || (i[a] = []), i[a].push(t);
        }), e.likeArr = i, this.setData(e), this.getDataAccountList(), this.getAddressProvince();
    },
    methods: {
        setEditUserShow: function() {
            this.setData({
                editUserShow: !this.data.editUserShow
            });
        },
        setSelectUserShow: function() {
            this.setData({
                selectUserShow: !this.data.selectUserShow
            });
        },
        setTipsShow: function() {
            this.setData({
                tipsShow: !this.data.tipsShow
            });
        },
        _handClickSpecs: function(t) {
            if (this.data.rechargeSpecId != t.id) {
                for (var e = this.data.goodsInfo.has_many_options, a = [], o = 0; o < e.length; o++) a.push(e[o]);
                this.setData({
                    displayOptions: a,
                    optionsId: 0
                });
            }
        },
        handClickOptions: function(t) {
            var e = t.currentTarget.dataset.item;
            this.setData({
                optionsId: e.id
            });
        },
        onChangeSwipeIndex: function(t) {
            var e = t.detail.current;
            this.setData({
                swipeIndex: e
            });
        },
        gotoDetailV2: function(t) {
            var e = t.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + e
            });
        },
        gotoChat: function(t) {
            var e = t.currentTarget.dataset.cservice + "&goods_id=" + this.data.goodsId;
            wx.navigateTo({
                url: e,
                fail: function(t) {
                    a.tips("客服路由出错");
                }
            });
        },
        setCserviceFlag: function() {
            this.setData({
                show1: !this.data.show1
            });
        },
        gotoOrderList: function() {
            wx.navigateTo({
                url: "/packageA/member/myOrder_v2/myOrder_v2"
            });
        },
        gotoIndex: function() {
            wx.reLaunch({
                url: "/packageG/index/index"
            });
        },
        setPosterShow: function() {
            this.setData({
                posterShow: !0
            });
        },
        setTopping: function() {
            wx.pageScrollTo({
                scrollTop: 0
            });
        },
        sendRecharge: function() {
            var t = this.data, e = t.goodsId, o = t.optionsId;
            return this.data.currentAccount ? o <= 0 ? a.tips("请选择充值金额") : void wx.navigateTo({
                url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&total=1&&goodsId=" + e + "&optionsId=" + o + "&account_id=" + this.data.currentAccount.id + "&electricity=electricity"
            }) : a.tips("请先添加户号");
        },
        tapSelect_btn: function() {
            this.setData({
                tapSelect: !this.data.tapSelect
            });
        },
        checkProvince: function(t) {
            var e = t || this.data.form_province;
            return "广东省" == e || ("广西壮族自治区" == e || ("云南省" == e || ("贵州省" == e || ("海南省" == e || ("澳门特别行政区" == e || "香港特别行政区" == e)))));
        },
        saveBox: function() {
            var t = this;
            if (a._isTextEmpty(this.data.form_account_name)) return a.tips("填写户名");
            if (a._isTextEmpty(this.data.form_account_number)) return a.tips("请输入缴费户号");
            if (a._isTextEmpty(this.data.form_province) || a._isTextEmpty(this.data.form_city)) return a.tips("请选择所在省市");
            var e = this.checkProvince();
            if (e) {
                if (a._isTextEmpty(this.data.codeValue)) return void wx.showModal({
                    title: "",
                    content: "请输入身份证/营业执照/机构代码后6位",
                    showCancel: !1
                });
                if (this.data.codeValue.length < 6) return void wx.showModal({
                    title: "",
                    content: "请输入身份证/营业执照/机构代码后6位",
                    showCancel: !1
                });
            }
            var o = a.getNetAddresss("plugin.electricity-bill-pro.frontend.accountUser.saveAccount"), c = {
                account_name: this.data.form_account_name,
                account_number: this.data.form_account_number,
                province: this.data.form_province,
                city: this.data.form_city,
                charge_type: this.data.form_charge_type
            };
            e && (c.code = this.data.codeValue);
            var i = {
                form: c
            };
            this.data.AccountID && (i.id = this.data.AccountID), a._postNetWork({
                url: o,
                data: i,
                success: function(e) {
                    var o = e.data;
                    a.tips(o.msg), 1 == o.result && (t.setData({
                        AccountID: "",
                        editUserShow: !1
                    }), t.getDataAccountList());
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        newCreate: function() {
            this.setData({
                form_account_name: "",
                form_account_number: "",
                form_province: "",
                form_city: "",
                form_charge_type: 1,
                AccountID: "",
                editUserShow: !0,
                isProvinceShow: !1,
                codeValue: ""
            });
        },
        onChangeCurrentAccount: function(t) {
            for (var e = t.detail, a = 0; a < this.data.AccountList.length; a++) this.data.AccountList[a].id == e && this.setData({
                currentAccount: this.data.AccountList[a],
                radioAccount: e,
                selectUserShow: !1
            });
        },
        delIcon: function(o) {
            var c = this;
            return e(t.default.mark(function e() {
                var i, r;
                return t.default.wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return i = o.currentTarget.dataset.item, t.next = 3, a.confirm("确定删除吗？");

                      case 3:
                        if (t.sent) {
                            t.next = 6;
                            break;
                        }
                        return t.abrupt("return");

                      case 6:
                        r = a.getNetAddresss("plugin.electricity-bill-pro.frontend.accountUser.delAccount"), 
                        a._getNetWork({
                            url: r,
                            data: {
                                id: i.id
                            },
                            success: function(t) {
                                var e = t.data;
                                a.tips(e.msg), 1 == e.result && (i.id == c.data.currentAccount.id && c.setData({
                                    currentAccount: null
                                }), c.getDataAccountList());
                            },
                            fail: function(t) {
                                console.log(t);
                            }
                        });

                      case 8:
                      case "end":
                        return t.stop();
                    }
                }, e);
            }))();
        },
        editIcon: function(t) {
            var e = t.currentTarget.dataset.item;
            this.checkProvince(e.province) ? e.code ? this.setData({
                isProvinceShow: !0,
                codeValue: e.code
            }) : this.setData({
                isProvinceShow: !0,
                codeValue: ""
            }) : this.setData({
                isProvinceShow: !1
            }), this.setData({
                selectUserShow: !1,
                editUserShow: !0,
                form_account_name: e.account_name,
                form_account_number: e.account_number,
                form_province: e.province,
                form_city: e.city,
                form_charge_type: e.charge_type,
                AccountID: e.id
            });
        },
        getDataAccountList: function() {
            var t = this, e = a.getNetAddresss("plugin.electricity-bill-pro.frontend.accountUser.getAccountList");
            a._getNetWork({
                url: e,
                success: function(e) {
                    var a = e.data;
                    1 == a.result && (t.setData({
                        AccountList: a.data,
                        radioAccount: a.data[0] ? a.data[0].id : 0
                    }), t.setData({
                        currentAccount: a.data[0] ? a.data[0] : null
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        getAddressProvince: function() {
            var t = this, e = a.getNetAddresss("plugin.electricity-bill-pro.frontend.accountUser.getRegion");
            a._getNetWork({
                url: e,
                success: function(e) {
                    var a = e.data;
                    if (1 == a.result) {
                        var o = a.data;
                        t.setData({
                            provinceData: [ {
                                values: o,
                                className: "columnl"
                            }, {
                                values: o[0].children,
                                className: "column2"
                            } ]
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        onChangeChargeType: function(t) {
            this.setData({
                form_charge_type: t.detail
            });
        },
        setAddressShow_p: function() {
            this.setData({
                addressShow_p: !this.data.addressShow_p
            });
        },
        onChangeAddress: function(t) {
            var e = t.detail, a = e.picker, o = e.value;
            console.log(o), a.setColumnValues(1, o[0].children);
        },
        addressCallback: function(t) {
            var e = t.detail.value;
            this.setData({
                form_province: e[0].text,
                form_city: e[1].text,
                addressShow_p: !1
            }), 1 == this.checkProvince() ? this.setData({
                isProvinceShow: !0
            }) : this.setData({
                isProvinceShow: !1
            });
        }
    }
});